package net.esj.basic.dao.ann;


public class SqlHelper {

	public static String generateTableNameByEntityName(String entityName,boolean upper){
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<entityName.length();i++){
			char c = entityName.charAt(i);
			if(c>='A'&&c<='Z'){
				sb.append("_").append(((char)(c+32)));
			}else{
				sb.append(c);
			}
		}
		String str = sb.toString();
		if(upper){
			str = str.toUpperCase();
		}
		return str;
	}
	
	public static String generateColumnNameByFieldName(String fieldName,boolean upper){
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<fieldName.length();i++){
			char c = fieldName.charAt(i);
			if(c>='A'&&c<='Z'){
				sb.append("_").append(((char)(c+32)));
			}else{
				sb.append(c);
			}
		}
		String str = sb.toString();
		if(upper){
			str = str.toUpperCase();
		}
		return str;
	}
}
